package com.yehui.spring.aop.annotation;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author 业徽
 * @date 2021/7/27
 */
@Aspect
@Component
public class AnnotationAspect {

    @Around(value = "@annotation(com.yehui.spring.aop.annotation.Name)")
    public Object around(ProceedingJoinPoint joinPoint) {
        final MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        final Method method = signature.getMethod();
        final Name annotation = AnnotationUtils.getAnnotation(method, Name.class);
        final String value = annotation.value();
        System.out.println("method: " + method + " value: " + value);

        return null;
    }
}
